package com.cz.video.website.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import com.cz.video.common.annotation.LegalValidate;
import com.cz.video.common.annotation.Log;
import com.cz.video.common.core.controller.BaseController;
import com.cz.video.common.core.domain.PageQuery;
import com.cz.video.common.core.domain.R;
import com.cz.video.common.core.page.TableDataInfo;
import com.cz.video.common.core.validate.AddGroup;
import com.cz.video.common.core.validate.EditGroup;
import com.cz.video.common.enums.BusinessType;
import com.cz.video.common.utils.ValidatorUtils;
import com.cz.video.website.domain.WebsiteMediaTag;
import com.cz.video.website.domain.bo.WebsiteMediaTagBo;
import com.cz.video.website.domain.vo.WebsiteMediaTagVo;
import com.cz.video.website.service.IWebsiteMediaTagService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 标签表 前端控制器
 * </p>
 *
 * @author 洪圆胜
 * @since 2023-10-15
 */
@Tag(name = "标签管理")
@RestController
@Validated
@RequiredArgsConstructor
@RequestMapping("/website/tag")
public class WebsiteMediaTagController extends BaseController {

    private final IWebsiteMediaTagService websiteMediaTagService;

    @SaCheckPermission("website:mediaTag:add")
    @Log(title = "添加标签", businessType = BusinessType.INSERT)
    @LegalValidate
    @Operation(summary = "添加标签")
    @PostMapping("")
    public R<Void> add(@RequestBody @Validated(value = {AddGroup.class}) WebsiteMediaTagBo websiteMediaTag){
        return toAjax(websiteMediaTagService.addMediaTag(websiteMediaTag));
    }

    @SaCheckPermission("website:mediaTag:delete")
    @Log(title = "删除标签", businessType = BusinessType.DELETE)
    @Operation(summary = "删除标签")
    @DeleteMapping("/{id}")
    public R<Void> delete(@PathVariable Long id) { return toAjax(websiteMediaTagService.removeById(id));
    }

    @SaCheckPermission("website:mediaTag:edit")
    @Log(title = "更新标签", businessType = BusinessType.UPDATE)
    @Operation(summary = "更新标签")
    @LegalValidate
    @PutMapping("")
    public R<Void> edit(@RequestBody WebsiteMediaTagBo websiteMediaTag){
        ValidatorUtils.validate(websiteMediaTag, EditGroup.class);
        return toAjax(websiteMediaTagService.update(websiteMediaTag));
    }

    @Log(title = "查看标签", businessType = BusinessType.SELECT)
    @Operation(summary = "查看标签")
    @GetMapping("/{id}")
    public R<WebsiteMediaTag> view(@PathVariable Long id){
        WebsiteMediaTag websiteMediaTag = websiteMediaTagService.getById(id);
        return R.ok(websiteMediaTag);
    }

    @SaIgnore
    @Operation(summary = "分页查询标签")
    @GetMapping("/list")
    public TableDataInfo<WebsiteMediaTagVo> page(WebsiteMediaTagBo websiteMediaTag, PageQuery pageQuery){
        return websiteMediaTagService.page(websiteMediaTag,pageQuery);
    }
}
